package liuch.stack;

import org.apache.commons.lang3.builder.ReflectionToStringBuilder;

import java.util.LinkedList;

/**
 * 〈一句话功能简述〉<br>
 * 〈基于LinkedList实现栈结构〉
 *
 * @author liuch on 2018/3/18.
 * @see [相关类/方法]（可选）
 * @since [产品/模块版本] （可选）
 */
public class Stack<T> {

    private LinkedList<T> list = new LinkedList<T>();

    public void push(T t) {
        this.list.addFirst(t);
    }

    public T peek() {
        return this.list.getFirst();
    }

    public T pop() {
        return this.list.removeFirst();
    }

    public boolean empty() {
        return this.list.isEmpty();
    }

    @Override
    public String toString() {
        return ReflectionToStringBuilder.toString(this);
    }

    public static void main(String[] args) {
//        Stack<String> stringStack = new Stack<String>();
//        for (String s : "sf d trgr trt ef".split(" ")){
//            stringStack.push(s);
//        }
//        System.out.println(stringStack);
        java.util.Stack<Integer> stack = new java.util.Stack<Integer>();
        for (int i = 0; i < 10; i++) {
            stack.push(i);
        }
        System.out.println(stack);
        System.out.println(stack.peek());
    }
}
